$(document).ready(function(){

	$('#urlform').submit(function(eve){
		eve.preventDefault();
		var purposeUrl=$("#purposeUrl").val();
		
		$.post(base_url+'urlform/urlsub',{purposeUrl:purposeUrl},function(html){
				//$('#task').after("load content");
				//$('#task').text("").hide();
				
			//	console.log(html);
				$('.shortenedBitlyListListBox').hide('slow');
				$('.shortened_results_list').after(html);
				$('.shortenedBitlyListListBox').show('slow');
				$("#purposeUrl").val('');
				
				
		});
	});
	//memUrlSub
	$('#memUrlSub').submit(function(eve){
		eve.preventDefault();
		var purposeUrl=$("#purposeUrl").val();
		var domain=$("#domain").val();
		var shorturl=$("#shorturl").val();
		console.log(purposeUrl);
	//	console.log(domain);
	//	console.log(shorturl);
		$.post(base_url+'urlshort/urlform/memUrlSub',{purposeUrl:purposeUrl,domain:domain,shorturl:shorturl},function(data){				
			//	console.log(data);
			data=eval(data);
			if(data[0].error==0){		
				var html="<li class='linkCapsule_link clearfix' hash='baobao' style='display: none; background-color: rgb(255, 255, 255); '><div class='shortened_url clearfix'>";
					html+="<a class='short_url' href='"+data[0].shorturl+"' target='_blank'><span class='hash'>"+data[0].shorturl.replace("http://","")+"</span></a><span class='copy_customize flash'>";
					html+="<a href='#' class='customize_button'>Customize</a><span class='copy_separator'> | </span><a href='#' data-href='http://bit.ly/baobao' class='copy_button' style='text-indent: 0px; '>Copy<span class='clippy'></span><div style='position: absolute; left: 0px; top: 0px; width: 37px; height: 28px; z-index: 99; '>";
					html+="<embed id='ZeroClipboardMovie_1' src='public_html/flash/ZeroClipboard.swf' loop='false' menu='false' quality='best' bgcolor='#ffffff' width='37' height='28' name='ZeroClipboardMovie_1' align='middle' allowscriptaccess='always' allowfullscreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' flashvars='id=1&amp;width=37&amp;height=28' wmode='transparent'></div></a></span></div>";
					html+="<a class='realtime_stats' href='http://bit.ly/baobao+' target='_blank'>Info Page+</a>";
					html+="<a class='long_link' href='"+data[0].purposeUrl+"' target='_blank' title='"+data[0].purposeUrl+"'>"+data[0].purposeUrl+"</a></li>";
		
					$('.shortenedBitlyListListBox').hide('slow');
					$('.shortened_results_list').after(html);
					$('.linkCapsule_link').show('slow');
					$('.shortenedBitlyListListBox').show('slow');
			//		$("#purposeUrl").val('');
				//历史记录添加	
				var historyHtml="<div class='resultsItemContainer' style='display:none;'>";
				historyHtml+="<div class='resultsColumn2 resultsColumn'><form class='bundle_cb_form'><fieldset><input type='checkbox' class='item_cb' value='y6Hq1K'></fieldset></form><div class='statsList' style='display: block; '><div class='userStats'><h4><a title='Get Real-time Metrics for this link' type='y6Hq1K' href='/y6Hq1K+'>0</a></h4></div><div class='statsSeparator'>out of</div><div class='globalStats'><a type='xHBe6I' href='/xHBe6I+'>0</a></div></div><div class='hr'><hr></div></div> <div class='resultsColumn4 resultsColumn'>";
				historyHtml+="<div class='linkTitleContainer'><h4 class='linkTitle'><img class='historyFavicon' src='/favicon/xHBe6I.png' width='16' height='16' alt='favicon' border='0'><a title='"+data[0].purposeUrl+"' href='"+data[0].shorturl+"'>"+data[0].purposeUrl+"</a></h4></div><div class='long_url_display_more'><a href='"+data[0].purposeUrl+"' title='"+data[0].purposeUrl+"'>"+data[0].purposeUrl+"</a></div><div class='short_url_display_more'><a href='"+data[0].shorturl+"' title='"+data[0].shorturl+"' class='hash'>"+data[0].shorturl.replace("http://","")+"</a><span class='copy_customize flash'><a style='text-indent: 0px; ' class='copy_button' href='#' data-href='"+data[0].shorturl+"'> - Copy<span class='clippy'></span><div style='position: absolute; left: 0px; top: 0px; width: 37px; height: 28px; z-index: 99; '><embed id='ZeroClipboardMovie_6' src='/s/v404/flash/zeroclipboard/ZeroClipboard.swf' loop='false' menu='false' quality='best' bgcolor='#ffffff' width='37' height='28' name='ZeroClipboardMovie_6' align='middle' allowscriptaccess='always' allowfullscreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' flashvars='id=6&amp;width=37&amp;height=28' wmode='transparent'></div></a></span></div></div>";
				historyHtml+="<div class='resultsColumn5 resultsColumn'><a href='/y6Hq1K+' title='Real-time stats for bit.ly/y6Hq1K+'>Info Page+</a></div><div class='resultsColumn6 resultsColumn'><div class='dateAndTimeBox'>  41 mins ago</div></div><div class='resultsColumn7 resultsColumn'><div class='optionsDropDownContainer' type='y6Hq1K' alt='http://bit.ly/y6Hq1K'><ul class='toolsDropList'><li class='topLevel'><div class='optionsToolPanel'><b class='topLeft'></b><b class='topRight'></b><span>Options</span></div><ul class='toolsList'><li class='toolsListShare'><a class='optionsShareButton' href='#'>Share</a></li><li class='optionsCopyButtonContainer'><a class='optionsCopyButton' href='#'>Copy</a><div style='position: absolute; left: 0px; top: 0px; z-index: 99; width: 65px; height: 20px; '><embed id='ZeroClipboardMovie_8' src='/s/v404/flash/zeroclipboard/ZeroClipboard.swf' loop='false' menu='false' quality='best' bgcolor='#ffffff' width='60' height='20' name='ZeroClipboardMovie_8' align='middle' allowscriptaccess='always' allowfullscreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' flashvars='id=8&amp;width=60&amp;height=20' wmode='transparent'></div></li><li class='toolsListDelete'><a class='optionsDeleteButton' href='#'>Archive</a></li><li class='editableTitleListItem'><a class='editableTitleButton' href='#'>Edit</a></li></ul></li></ul></div></div><div class='moreInfo row2'><div id='history_preview_xHBe6I' class='link_preview'></div></div><div class='hr'><hr></div></div> <!-- end .resultsItemContainer -->";
					//resultsItemContainer
				$('.resultsBarContainer').after(historyHtml);
				setTimeout(newHistoryUrl,1500);
			
			}else{
				var html="<li class='linkCapsule_link clearfix' hash='baobao' style='display: block; background-color: rgb(255, 255, 255); '>"+data[0].errorinfo+"</li>";
				$('.shortenedBitlyListListBox').hide('slow');
				$('.shortened_results_list').after(html);
				$('.shortenedBitlyListListBox').show('slow');
			}
		});
	});	
	function newHistoryUrl(){
		$('.resultsItemContainer').show('slow');
	}
/*	$('#task').live('click',function(eve){
		eve.preventDefault();
		$.get('test/task',function(html){
				//$('#task').after("load content");
				//$('#task').text("").hide();
				//console.log(html);
				$('#shortenedBitlyListListBox').text(html).show('slow');
		});
	});	
	*/
});